/*
 * Copyright (C) 2014 Lucid Wolf
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.lucidhex.hex;

/**
 *
 * @author Wolf
 */
public class LucidCoord{
    private final double[][] toErfFromMap = {{Math.sqrt(3.0)/3, -1.0/3.0},{0.0, 2.0/3.0}};
    private double r = 0;
    private double q = 0;
    public LucidCoord(double q, double r){
        this.q = q;
        this.r = r;
    }
    public LucidCoord(double a, double b, double c){
        this.q = a;
        this.r = c;
    }
    public LucidCoord(PlaneCoord mC){
        q = mC.X()* toErfFromMap[0][0] + mC.Y()* toErfFromMap[0][1];
        r = mC.X()* toErfFromMap[1][0] + mC.Y()* toErfFromMap[1][1];
    }    
    public double R(){
        return r;
    }
    public double Q(){
        return q;
    }
    public double A(){
        return q;
    }
    public double B(){
        return -q-r;
    }
    public double C(){
        return r;
    }
    public double[] toArray() {
        double[] out = {q, r};
        return out;
    }
    public static double distance (LucidCoord c1, LucidCoord c2){
        return Math.max(Math.abs(c1.A()-c2.A()), Math.max(Math.abs(c1.B()-c2.B()),Math.abs(c1.C()-c2.C())));
    }
}
